package com.dingwei.lesyndrome.mvp.presenter;

import com.dingwei.lesyndrome.adapter.GamCircleListAdapter;
import com.dingwei.lesyndrome.base.FailsBean;
import com.dingwei.lesyndrome.base.MyBaseBean;
import com.dingwei.lesyndrome.bean.GamCircleListBean;
import com.dingwei.lesyndrome.custom.myCallback;
import com.dingwei.lesyndrome.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.URLS;
import com.lihao.baselibrary.base.basePresenter;

import org.xutils.http.RequestParams;
import org.xutils.x;

import java.math.RoundingMode;

/**
 * Created by lihao on 2017/9/12.
 */

public class GamCircleFragmentPresenter extends basePresenter {

    private Contract.GamCircleFragmentView gamCircleFragmentView;

    public GamCircleFragmentPresenter(Contract.GamCircleFragmentView view) {
        super(view);
        this.gamCircleFragmentView = view;
    }

    public void initData(String id, int page, final boolean isRefresh, boolean isShowDiaolg) {
        RequestParams rp = new RequestParams(URLS.HOST + URLS.CIRCLE_LIST);
        rp.addBodyParameter("cpage", page + "");
        rp.addBodyParameter("cid", id);
        rp.addBodyParameter("sessionid", BaseActivity.value.getToken());
        x.http().post(rp, new myCallback(BaseActivity.context, GamCircleListBean.class, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                GamCircleListBean bean = (GamCircleListBean) baseBean;
                if (isRefresh) {
                    gamCircleFragmentView.onRefresh(bean);
                } else {
                    gamCircleFragmentView.onLoadMore(bean);
                }
            }

            @Override
            public void fail(FailsBean baseBean, String result) {
                gamCircleFragmentView.onFail();
            }
        });
    }

    public void like(String id, final int positon) {

        RequestParams rp = new RequestParams(URLS.HOST+URLS.OPAGREE);
        rp.addBodyParameter("cid", id);
        rp.addBodyParameter("sessionid", BaseActivity.value.getToken());
        x.http().post(rp, new myCallback(BaseActivity.context, MyBaseBean.class, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                gamCircleFragmentView.likeSuccess(positon);
            }

            @Override
            public void fail(FailsBean baseBean, String result) {

            }
        });

    }
}
